package com.ruoyi.binance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.binance.domain.BinanceAverageBuySell;
import com.ruoyi.binance.service.IBinanceAverageBuySellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 均价买卖Controller
 * 
 * @author zq
 * @date 2025-08-15
 */
@RestController
@RequestMapping("/binance/avebuysell")
public class BinanceAverageBuySellController extends BaseController
{
    @Autowired
    private IBinanceAverageBuySellService binanceAverageBuySellService;

    /**
     * 查询均价买卖列表
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinanceAverageBuySell binanceAverageBuySell)
    {
        startPage();
        List<BinanceAverageBuySell> list = binanceAverageBuySellService.selectBinanceAverageBuySellList(binanceAverageBuySell);
        return getDataTable(list);
    }

    /**
     * 导出均价买卖列表
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:export')")
    @Log(title = "均价买卖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinanceAverageBuySell binanceAverageBuySell)
    {
        List<BinanceAverageBuySell> list = binanceAverageBuySellService.selectBinanceAverageBuySellList(binanceAverageBuySell);
        ExcelUtil<BinanceAverageBuySell> util = new ExcelUtil<BinanceAverageBuySell>(BinanceAverageBuySell.class);
        util.exportExcel(response, list, "均价买卖数据");
    }

    /**
     * 获取均价买卖详细信息
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(binanceAverageBuySellService.selectBinanceAverageBuySellByCode(code));
    }

    /**
     * 新增均价买卖
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:add')")
    @Log(title = "均价买卖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinanceAverageBuySell binanceAverageBuySell)
    {
        return toAjax(binanceAverageBuySellService.insertBinanceAverageBuySell(binanceAverageBuySell));
    }

    /**
     * 修改均价买卖
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:edit')")
    @Log(title = "均价买卖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinanceAverageBuySell binanceAverageBuySell)
    {
        return toAjax(binanceAverageBuySellService.updateBinanceAverageBuySell(binanceAverageBuySell));
    }

    /**
     * 删除均价买卖
     */
    @PreAuthorize("@ss.hasPermi('binance:avebuysell:remove')")
    @Log(title = "均价买卖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(binanceAverageBuySellService.deleteBinanceAverageBuySellByCodes(codes));
    }
}
